﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace MoveNext.IO.Grf
{
    public class BaseReader : BinaryReader
    {
        private Encoding encoding;

        public BaseReader(Stream input)
            : this(input, GrfConst.Encoding)
        {
        }

        public BaseReader(Stream input, Encoding encoding)
            : base(input)
        {
            this.encoding = encoding;
        }

        public virtual string ReadString(int bytes)
        {
            return this.encoding.GetString(this.ReadBytes(bytes));
        }

        public override string ReadString()
        {
            List<byte> bytes = new List<byte>();
            byte b;
            while ((b = this.ReadByte()) != 0)
            {
                bytes.Add(b);
            }
            return this.encoding.GetString(bytes.ToArray());
        }
    }
}
